home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacHaskell 2.2 / progs / lib / hbc / Hash.hs next >
Encoding:
Text File  |  1994-09-27  |  1.9 KB  |  50 lines  |  [TEXT/YHS2]

  1.  () where
  2.     hash x = 0
  3.  
  4. instance Hashable (a -> b) where
  5.     hash x = 0
  6.  
  7. instance Hashable a => Hashable [a] where
  8.     hash x = sum (map hash x)
  9.  
  10. instance (Hashable a, Hashable b) => Hashable (a,b) where
  11.     hash (a,b) = hash a + 3 * hash b
  12.  
  13. instance (Hashable a, Hashable b, Hashable c) => Hashable (a,b,c) where
  14.     hash (a,b,c) = hash a + 3 * hash b + 5 * hash c
  15.  
  16. instance (Hashable a, Hashable b, Hashable c, Hashable d) => Hashable (a,b,c,d) where
  17.     hash (a,b,c,d) = hash a + 3 * hash b + 5 * hash c + 7 * hash d
  18.  
  19. instance (Hashable a, Hashable b, Hashable c, Hashable d, Hashable e) => Hashable (a,b,c,d,e) where
  20.     hash (a,b,c,d,e) = hash a + hash b + hash c + hash d + hash e
  21.  
  22. instance Hashable Bool where
  23.     hash False = 0
  24.     hash True = 1
  25.  
  26. instance (Integral a, Hashable a) => Hashable (Ratio a) where
  27.     hash x = hash (denominator x) + hash (numerator x)
  28.  
  29. instance (RealFloat a, Hashable a) => Hashable (Complex a) where
  30.     hash (x :+ y) = hash x + hash y
  31.  
  32. instance (Hashable a, Hashable b) => Hashable (Assoc a b) where
  33.     hash (x := y) = hash x + hash y
  34.  
  35. instance (Ix a) => Hashable (Array a b) where
  36.     hash x = 0 -- !!!
  37.  
  38. instance Hashable Request where
  39.     hash x = 0 -- !!
  40.  
  41. instance Hashable Response where
  42.     hash x = 0 -- !!
  43.  
  44. instance Hashable IOError where
  45.     hash x = 0 -- !!
  46.  
  47. hashToMax maxhash x =
  48.     let h = abs (hash x)
  49.     in  if h < 0 then 0 else h `rem` maxhash
  50.